package com.bayi.storage.activity

import android.view.View
import com.bayi.storage.R
import com.bayi.storage.base.BaseActivity
import com.bayi.storage.base.BaseViewModel
import com.bayi.storage.crash.CustomActivityOnCrash
import com.bayi.storage.crash.config.CaocConfig
import com.bayi.storage.databinding.ActivityCustomErrorBinding
import com.bayi.storage.viewModel.CustomErrorViewModel

/**
 * @author Administrator on 2024-05-31.
 *
 *
 * 站在顶峰 看世界
 * 落到谷底 思人生
 */
class CustomErrorActivity : BaseActivity<CustomErrorViewModel,ActivityCustomErrorBinding>() {

//    override fun createViewModel(): CustomErrorViewModel {
//        return CustomErrorViewModel(application)
//    }

    override fun createViewBinding(): ActivityCustomErrorBinding {
        return ActivityCustomErrorBinding.inflate(layoutInflater)
    }

    override fun initView() {
        binding.errorDetails.text = CustomActivityOnCrash.getStackTraceFromIntent(intent)

        val config: CaocConfig? = CustomActivityOnCrash.getConfigFromIntent(intent)

        if (config == null) {
            //This should never happen - Just finish the activity to avoid a recursive crash.
            finish()
            return
        }

        if (config.isShowRestartButton && config.restartActivityClass != null) {
            binding.restartButton.setText(R.string.restart_app)
            binding.restartButton.setOnClickListener {
                CustomActivityOnCrash.restartApplication(
                    this@CustomErrorActivity,
                    config
                )
            }
        } else {
            binding.restartButton.setOnClickListener {
                CustomActivityOnCrash.closeApplication(
                    this@CustomErrorActivity,
                    config
                )
            }
        }
    }
}